home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / HENSA / MATHS / PLPLOT / PLPLOT.ZIP / sys / RISC_OS / c / arcdraw next >
Encoding:
Text File  |  1996-03-01  |  19.5 KB  |  750 lines

  1. /* ///////////////////////////////////////////////////////////////////
  2. // $Id: arcdraw.c,v 1.0 1995/08/29 06:03:13  Exp $
  3. // $Log: arcdraw.c.c,v $
  4.  *
  5.  * Revision 1.0 1.0 1995/08/29 06:03:13
  6.  * Acorn RISC OS draw driver, contributed by Maurizio Ferrari
  7.  * (ferrari@bologna.marelli.it).
  8.  *
  9. //
  10. //  File:       arcdraw.c
  11. //
  12. //  Descript:   RISC OS draw file drivers
  13. //
  14. //  Library:    ---
  15. //
  16. //  Requires:   ---
  17. //
  18. //  Public:     plD_init_arcdraw()
  19. //              plD_line_arcdraw()
  20. //              plD_polyline_arcdraw()
  21. //              plD_eop_arcdraw()
  22. //              plD_bop_arcdraw()
  23. //              plD_tidy_arcdraw()
  24. //              plD_state_arcdraw()
  25. //              plD_esc_arcdraw()
  26. //
  27. //              pldummy_arcdraw()
  28. //
  29. //  Private:    arcdraw_initialize_pls()
  30. //
  31. //  Notes:      ---
  32. //
  33. //  Revisions:
  34. /////////////////////////////////////////////////////////////////// */
  35.  
  36. #include "plDevs.h"
  37.  
  38. #if defined(PLD_arcdraw)
  39.  
  40. /*#define DEBUG_ENTER*/
  41.  
  42. #include "plplotP.h"
  43. #include <stdio.h>
  44. #include <string.h>
  45. #include "drivers.h"
  46. #include "arcdraw.h"
  47.  
  48. /* top level declarations */
  49. /* Page sizes */
  50.  
  51. #define ARCDRAW_XMIN  100
  52. #define ARCDRAW_XMAX  5000
  53. #define ARCDRAW_YMIN  200
  54. #define ARCDRAW_YMAX 3500
  55. #define ARCDRAW_XRATIO 4.
  56. #define ARCDRAW_YRATIO 4.
  57. #define SCALE_FACTOR  100
  58. #define TRANSPARENT 0xFFFFFFFF
  59. #define BLACK 0x00000000
  60. #define PATH_BUFFER_SIZE 32000
  61. #define FREE(ptr) if((ptr)!=NULL){free((void *)ptr);ptr=NULL;}
  62.  
  63. enum {AT_BOP, DRAWING, AT_EOP};
  64.  
  65. /* Struct to hold device-specific info. */
  66.  
  67. typedef struct {
  68.     PLFLT pxlx, pxly;
  69.     PLINT xold, yold;
  70.  
  71.     PLINT xmin, xmax, xlen;
  72.     PLINT ymin, ymax, ylen;
  73.  
  74.     PLINT xmin_dev, xmax_dev, xlen_dev;
  75.     PLINT ymin_dev, ymax_dev, ylen_dev;
  76.  
  77.     PLFLT xscale_dev, yscale_dev;
  78.  
  79.     PLINT path_is_open;
  80.     PLINT width_has_changed;
  81.     PLINT color_0_has_changed;
  82.     PLINT color_1_has_changed;
  83.     PLINT x1st;
  84.     PLINT y1st;
  85.     PLINT xlast;
  86.     PLINT ylast;
  87.     PLINT fill_req;
  88.     PLINT must_close;
  89.     PLINT path_is_valid;
  90.     PLColor fill_color;
  91.     PLINT graph_isopen;
  92.     PLINT path_offset;
  93.     PLINT *path_ptr;
  94.     PLINT path_len;
  95. } DrawDev;
  96.  
  97.  
  98. /*local prototypes */
  99. static void arcdraw_end_path(PLStream *, pldraw_pathstrhdr * );
  100. static void arcdraw_start_path(PLStream *);
  101. static void arcdraw_initialize_pls(PLStream *);
  102. static void arcdraw_change_colour0(PLStream *);
  103. static void arcdraw_change_colour1(PLStream *);
  104. static void arcdraw_change_width(PLStream *);
  105.  
  106. static int make_file_hdr(PLStream *pls, pldraw_fileheader *, pldraw_bboxtyp *);
  107. static int make_path_hdr(PLStream *, pldraw_pathstrhdr *, pldraw_pathstyle *, pldraw_bboxtyp *);
  108. static int end_obj(PLStream *pls, pldraw_pathstrhdr *);
  109. static int add_to_path(PLStream *pls, int);
  110. static int move_to(PLStream *pls, int, int);
  111. static int line_to(PLStream *pls, int, int);
  112. static int close_path(PLStream *pls);
  113. static int end_path(PLStream *pls);
  114. static int rectangle(PLStream *pls, int , int , int , int );
  115. static void set_bbox(PLStream *pls, int x0, int y0, int x1, int y1, pldraw_bboxtyp * bbp);
  116. static unsigned int set_colour(PLColor);
  117.  
  118. pldraw_fileheader filehdr, *fhp = &filehdr;
  119. pldraw_pathstrhdr objh, *oph = &objh;
  120. pldraw_pathstyle  pstyle, *ps = &pstyle;
  121. pldraw_bboxtyp    bbox, rect_box, *pbb = &bbox, *rbp = &rect_box;
  122.  
  123. /*----------------------------------------------------------------------*\
  124.  * arcdraw_initialize_pls()
  125.  *
  126.  * Initialize plot stream
  127. \*----------------------------------------------------------------------*/
  128.  
  129. static void
  130. arcdraw_initialize_pls(PLStream *pls)
  131. {
  132.  
  133.     DrawDev *dev;
  134.  
  135.     dbug_enter("arcdraw_initialize_pls");
  136.     pls->termin = 0;            /* not an interactive terminal */
  137.     pls->icol1 = 1;
  138.     pls->bytecnt = 0;
  139.     pls->page = 0;
  140.     pls->family = 1;            /* file has family */
  141.     pls->output_type = 0;       /* 0 for file output type */
  142.     pls->dev_fill0 = 1;        /* Can do solid fills */
  143.     pls->dev_fill1 = 1;        /* Can do pattern fills */
  144.     pls->color = 1;
  145.     pls->nopause = 1;
  146.  
  147.     plFamInit(pls);         /* Initialize family file info */
  148.  
  149.     plOpenFile(pls);            /* get file name if not already set */
  150.  
  151.  
  152.     dbug_enter("arcdraw_initialize_pls: allocating DrawDev memory");
  153.     pls->dev = calloc(1, (size_t) sizeof(DrawDev));
  154.     if (pls->dev == NULL) {
  155.     plexit("arcdraw_init: Out of memory.");
  156.     }
  157.  
  158.     dev = (DrawDev *) pls->dev;
  159.     /*clear local work variables*/
  160.     dev->path_is_open = FALSE;
  161.     dev->width_has_changed = FALSE;
  162.     dev->color_0_has_changed = FALSE;
  163.     dev->color_1_has_changed = FALSE;
  164.     dev->x1st = 0;
  165.     dev->y1st = 0;
  166.     dev->xlast = 0;
  167.     dev->ylast = 0;
  168.     dev->fill_req = FALSE;
  169.     dev->must_close = FALSE;
  170.     dev->path_is_valid = FALSE;
  171.     dev->graph_isopen = TRUE;
  172.     dev->xmin = ARCDRAW_XMIN;
  173.     dev->xmax = ARCDRAW_XMAX;
  174.     dev->ymin = ARCDRAW_YMIN;
  175.     dev->ymax = ARCDRAW_YMAX;
  176.  
  177.     dev->xold = UNDEFINED;
  178.     dev->yold = UNDEFINED;
  179.     dev->xlen = dev->xmax - dev->xmin;
  180.     dev->ylen = dev->ymax - dev->ymin;
  181.     dev->xscale_dev = SCALE_FACTOR;
  182.     dev->yscale_dev = SCALE_FACTOR;
  183.     dev->path_offset = 0;
  184.     dev->path_len = PATH_BUFFER_SIZE;
  185.     dev->path_ptr = (int*) calloc(dev->path_len, sizeof(int));
  186.     if (dev->path_ptr == NULL) {
  187.       plexit("plD_bop_arcdraw: failed to allocate memory for Draw path");
  188.     }
  189.  
  190.  
  191.     plP_setpxl((PLFLT) ARCDRAW_XRATIO, (PLFLT) ARCDRAW_YRATIO);
  192.     plP_setphy(dev->xmin, dev->xmax, dev->ymin, dev->ymax);
  193.     dbug_enter("arcdraw_initialize_pls: exiting");
  194. }
  195.  
  196. /*----------------------------------------------------------------------*\
  197.  * plD_init_arcdraw()
  198.  *
  199.  * Initialize device.
  200. \*----------------------------------------------------------------------*/
  201.  
  202. void
  203. plD_init_arcdraw(PLStream *pls)
  204. {
  205.     arcdraw_initialize_pls(pls);   /* initialize plot stream */
  206. }
  207.  
  208.  
  209. /*----------------------------------------------------------------------*\
  210.  * plD_bop_arcdraw()
  211.  *
  212.  * Set up for the next page.
  213.  * Advance to next family file if necessary (file output).
  214. \*----------------------------------------------------------------------*/
  215.  
  216. void
  217. plD_bop_arcdraw(PLStream *pls)
  218. {
  219.     DrawDev *dev = (DrawDev *) pls->dev;
  220.  
  221.     dev->xold = UNDEFINED;
  222.     dev->yold = UNDEFINED;
  223.     dbug_enter("plD_bop_arcdraw");
  224.     fflush(pls->OutFile);
  225.     dbug_enter("plD_bop_arcdraw: plGetFam");
  226.     if (!pls->termin) {
  227.         plGetFam(pls);
  228.     }
  229.     pls->page++;
  230.     pls->famadv = 1; /*advance to next member*/
  231.     make_file_hdr(pls, fhp, pbb);
  232. /*   uncomment all this to create a default black back rectangle
  233.  *   make_path_hdr(pls, oph, ps, pbb);
  234.  *   oph->fillcolour = BLACK;
  235.  *   rectangle(pls, 0, 0, 5380, 3805);
  236.  *   pls->bytecnt += 15;
  237.  *   end_path(pls);
  238.  *   pls->bytecnt += 1;
  239.  *   end_obj(pls, oph);
  240.  *   dev->path_is_open = FALSE;
  241. */
  242.    make_path_hdr(pls, oph, ps, pbb);
  243.    oph->fillcolour = set_colour(pls->cmap0[0]);
  244.    rectangle(pls, 0, 0, 5380, 3805);
  245.    pls->bytecnt += 15;
  246.    end_path(pls);
  247.    pls->bytecnt += 1;
  248.    end_obj(pls, oph);
  249.    dev->path_is_open = FALSE;
  250.  
  251.    dbug_enter("plD_bop_arcdraw: exiting");
  252. }
  253.  
  254.  
  255. /*----------------------------------------------------------------------*\
  256.  * plD_eop_arcdraw()
  257.  *
  258.  * End of page.
  259. \*----------------------------------------------------------------------*/
  260.  
  261. void
  262. plD_eop_arcdraw(PLStream *pls)
  263. {
  264.     DrawDev *dev = (DrawDev *) pls->dev;
  265.  
  266.     dbug_enter("plD_eop_arcdraw");
  267.     if (dev->path_is_open != FALSE) {
  268.       arcdraw_end_path(pls, oph);
  269.       dev->path_is_open = FALSE;
  270.     }
  271. }
  272.  
  273. /*----------------------------------------------------------------------*\
  274.  * plD_tidy_arcdraw()
  275.  *
  276.  * Close graphics file or otherwise clean up.
  277. \*----------------------------------------------------------------------*/
  278.  
  279. void
  280. plD_tidy_arcdraw(PLStream *pls)
  281. {
  282.     DrawDev *dev = (DrawDev *) pls->dev;
  283. #ifdef __riscos
  284.     char *sys_string;
  285. #endif
  286.     dbug_enter("plD_tidy_arcdraw");
  287.     if (dev->path_is_open != FALSE) {
  288.       arcdraw_end_path(pls, oph);
  289.       dev->path_is_open = FALSE;
  290.     }
  291.     fclose(pls->OutFile);
  292.     if (dev->path_ptr != NULL) {
  293.       dbug_enter("plD_tidy_arcdraw: freeing dev->path_ptr");
  294.       FREE(dev->path_ptr);
  295.     }
  296.  
  297.     if (pls->dev != NULL) {
  298.       dbug_enter("plD_tidy_arcdraw: freeing pls->dev");
  299.       FREE(pls->dev);
  300.     }
  301. #ifdef __riscos
  302.     sys_string=malloc(sizeof(pls->FileName)+20);
  303.     if (sys_string == NULL) {
  304.       plwarn("malloc failed - cannot change filetype to AFF");
  305.     }
  306.     else {
  307.       sprintf(sys_string, "settype %s AFF", pls->FileName);
  308.       system(sys_string);
  309.       sprintf(sys_string, "filer_run %s", pls->FileName);
  310.       system(sys_string);
  311.     }
  312.     free(sys_string);
  313. #endif
  314.     dev->graph_isopen = FALSE;
  315. }
  316.  
  317. /*----------------------------------------------------------------------*\
  318.  * plD_state_arcdraw()
  319.  *
  320.  * Handle change in PLStream state (color, pen width, fill attribute, etc).
  321. \*----------------------------------------------------------------------*/
  322.  
  323. void
  324. plD_state_arcdraw(PLStream *pls, PLINT op)
  325. {
  326.     DrawDev *dev = (DrawDev *) pls->dev;
  327.  
  328.     switch (op) {
  329.  
  330.     case PLSTATE_WIDTH:
  331.         dev->width_has_changed = TRUE;
  332.         break;
  333.  
  334.     case PLSTATE_COLOR0:
  335.         dev->color_0_has_changed = TRUE;
  336.         break;
  337.  
  338.     case PLSTATE_COLOR1:
  339.         dev->color_1_has_changed = TRUE;
  340.         break;
  341.  
  342.     case PLSTATE_FILL:
  343.         break;
  344.  
  345.     default:
  346.         fprintf (stderr, "#PLSTATE_DEFAULT - code = %d ignored\n", op );
  347.         break;
  348.     }
  349. }
  350.  
  351. /*----------------------------------------------------------------------*\
  352.  * plD_esc_arcdraw()
  353.  *
  354.  * Escape function.
  355. \*----------------------------------------------------------------------*/
  356.  
  357. void
  358. plD_esc_arcdraw(PLStream *pls, PLINT op, void *ptr)
  359. {
  360.     DrawDev *dev = (DrawDev *) pls->dev;
  361.  
  362.     switch (op) {
  363.  
  364.       case PLESC_FILL:
  365.         dev->fill_req = TRUE;
  366.         dev->fill_color = pls->curcolor;
  367.         plD_polyline_arcdraw(pls, pls->dev_x, pls->dev_y, pls->dev_npts);
  368.     break;
  369.  
  370.       default:
  371. /*        fprintf(stderr, "#PLESC_DEFAULT - code = %d ignored\n", op );*/
  372.         break;
  373.     }
  374.  
  375. }
  376.  
  377. /*----------------------------------------------------------------------*\
  378.  * plD_line_arcdraw()
  379.  *
  380.  * Draw a line in the current color from (x1,y1) to (x2,y2).
  381. \*----------------------------------------------------------------------*/
  382.  
  383. void
  384. plD_line_arcdraw(PLStream *pls, short x1a, short y1a, short x2a, short y2a)
  385. {
  386.     DrawDev *dev = (DrawDev *) pls->dev;
  387.     int x1 = x1a, y1 = y1a, x2 = x2a, y2 = y2a;
  388.  
  389. /*    dbug_enter("plD_line_arcdraw");*/
  390.    /* Write out old path */
  391.     if (x1 != dev->xold || y1 != dev->yold) {
  392.       if (dev->path_is_open != FALSE) {
  393.         arcdraw_end_path(pls, oph);
  394.       }
  395.       arcdraw_start_path(pls);
  396.       pls->bytecnt += 3;
  397.       move_to (pls, x1, y1);
  398.       pls->bytecnt += 3;
  399.       dev->x1st = x1; dev->y1st = y1;
  400.       dev->color_0_has_changed = FALSE;
  401.       dev->color_1_has_changed = FALSE;
  402.     }
  403.     /* Add new point to path */
  404.     if (dev->width_has_changed == TRUE){
  405.       arcdraw_change_width(pls);
  406.     }
  407.     if (dev->color_0_has_changed == TRUE) {
  408.       arcdraw_change_colour0(pls);
  409.     }
  410.     if (dev->color_1_has_changed == TRUE) {
  411.       arcdraw_change_colour1(pls);
  412.     }
  413.     line_to (pls, x2, y2);
  414.     pls->bytecnt += 3;
  415.     dev->xlast = x2; dev->ylast = y2;
  416.     if ((dev->x1st != dev->xlast) || (dev->y1st != dev->ylast)) {
  417.       dev->path_is_valid = TRUE;
  418.     }
  419.  
  420.     dev->xold = x2;
  421.     dev->yold = y2;
  422. }
  423.  
  424. /*----------------------------------------------------------------------*\
  425.  * plD_polyline_arcdraw()
  426.  *
  427.  * Draw a polyline in the current color.
  428. \*----------------------------------------------------------------------*/
  429.  
  430. void
  431. plD_polyline_arcdraw(PLStream *pls, short *xa, short *ya, PLINT npts)
  432. {
  433.   register PLINT i;
  434.   DrawDev *dev = (DrawDev *) pls->dev;
  435.  
  436.   /* Write out old path */
  437.   if (dev->path_is_open != FALSE) {
  438.     arcdraw_end_path(pls, oph);
  439.   }
  440.   arcdraw_start_path(pls);
  441.   move_to (pls, xa[0], ya[0]);
  442.   pls->bytecnt += 3;
  443.   dev->x1st = xa[0]; dev->y1st = ya[0];
  444.   for (i = 1; i < npts; i++) {        /* Add new point to path */
  445.     line_to (pls, xa[i], ya[i]);
  446.     pls->bytecnt += 3;
  447.     dev->xlast = xa[i]; dev->ylast = ya[i] ;
  448.     if ((dev->x1st != dev->xlast) || (dev->y1st != dev->ylast)) {
  449.       dev->path_is_valid = TRUE;
  450.     }
  451.   }
  452.   arcdraw_end_path(pls,  oph);
  453.   dev->xold = xa[ npts - 1 ];
  454.   dev->yold = ya[ npts - 1 ];
  455. }
  456.  
  457.  
  458. /*----------------------------------------------------------------------*\
  459.  * arcdraw_start_path()
  460.  *
  461.  * start a new path function.
  462. \*----------------------------------------------------------------------*/
  463.  
  464. static void
  465. arcdraw_start_path(PLStream *pls)
  466. {
  467.     DrawDev *dev = (DrawDev *) pls->dev;
  468.  
  469.     dev->path_is_open = TRUE;
  470.     dev->path_is_valid = FALSE;
  471.     if ( pls->width == 0 ) {/*i.e. not initialised*/
  472. /*    draw_in_ptr->pathwidth = 500;*/
  473.     } else {
  474. /*    draw_in_ptr->pathwidth = 500* pls->width;*/
  475.     }
  476.     make_path_hdr(pls, oph, ps, pbb);
  477.     if (dev->fill_req == TRUE) {
  478.       dev->fill_req = FALSE;
  479.       dev->must_close = TRUE;
  480.     }
  481.       dev->color_0_has_changed = FALSE;
  482.       dev->color_1_has_changed = FALSE;
  483.  
  484. }
  485.  
  486. /*----------------------------------------------------------------------*\
  487.  * arcdraw_start_path()
  488.  *
  489.  * start a new path function.
  490. \*----------------------------------------------------------------------*/
  491.  
  492. static void
  493. arcdraw_end_path(PLStream *pls, pldraw_pathstrhdr * oph)
  494. {
  495.     DrawDev *dev = (DrawDev *) pls->dev;
  496.  
  497.     /* this should patch rogue draw paths */
  498.     if (dev->path_is_valid == FALSE) {
  499.       line_to (pls, dev->xlast+1, dev->ylast+1);
  500.       pls->bytecnt += 3;
  501.     }
  502.     if (dev->must_close == TRUE) {
  503.       oph->fillcolour = set_colour(pls->curcolor);
  504.       close_path(pls);
  505.       pls->bytecnt += 1;
  506.       dev->must_close = FALSE;
  507.     }
  508.     end_path(pls);
  509.     pls->bytecnt += 1;
  510.     end_obj(pls, oph);
  511.     dev->path_is_open = FALSE;
  512. }
  513.  
  514.  
  515. /*----------------------------------------------------------------------*\
  516.  * arcdraw_change_colour0()
  517.  *
  518.  * change colour0 function.
  519. \*----------------------------------------------------------------------*/
  520.  
  521. static void
  522. arcdraw_change_colour0(PLStream *pls)
  523. {
  524.      DrawDev *dev = (DrawDev *) pls->dev;
  525.  
  526.      dev->color_0_has_changed = FALSE;
  527.  
  528. }
  529.  
  530. /*----------------------------------------------------------------------*\
  531.  * arcdraw_change_colour1()
  532.  *
  533.  * change colour1 function.
  534. \*----------------------------------------------------------------------*/
  535.  
  536. static void
  537. arcdraw_change_colour1(PLStream *pls)
  538. {
  539.       DrawDev *dev = (DrawDev *) pls->dev;
  540.  
  541.       dev->color_1_has_changed = FALSE;
  542. }
  543.  
  544. /*----------------------------------------------------------------------*\
  545.  * arcdraw_change_width()
  546.  *
  547.  * change colour1 function.
  548. \*----------------------------------------------------------------------*/
  549.  
  550. static void
  551. arcdraw_change_width(PLStream *pls)
  552. {
  553.       DrawDev *dev = (DrawDev *) pls->dev;
  554.  
  555.       dev->width_has_changed = FALSE;
  556. }
  557.  
  558. /*----------------------------------------------------------------------*\
  559.  * set_bbox()
  560.  *
  561.  * set draw file bounding box.
  562. \*----------------------------------------------------------------------*/
  563.  
  564. void
  565. set_bbox(PLStream *pls, int x0, int y0, int x1, int y1, pldraw_bboxtyp * bbp)
  566. {
  567.         bbp->x0 = x0;
  568.         bbp->y0 = y0;
  569.         bbp->x1 = x1;
  570.         bbp->y1 = y1;
  571. }
  572.  
  573. /*----------------------------------------------------------------------*\
  574.  * make_file_hdr()
  575.  *
  576.  * create draw file header.
  577. \*----------------------------------------------------------------------*/
  578. int
  579. make_file_hdr(PLStream *pls, pldraw_fileheader * fhp, pldraw_bboxtyp * pbb)
  580. {
  581.         int             i = 0;
  582.         char           *type = "Draw", *appl = "PLPlot      ";
  583.  
  584.         while ((fhp->title[i++] = *type++) != '\0');
  585.         i = 0;
  586.         while ((fhp->progident[i++] = *appl++) != '\0');
  587.         fhp->majorstamp = 201;
  588.         fhp->minorstamp = 0;
  589.         set_bbox(pls, 0, 0, 0, 0, pbb);
  590.         fhp->bbox = *pbb;
  591.         fwrite(fhp, 1, sizeof(*fhp), pls->OutFile);
  592.         return (0);
  593. }
  594.  
  595. /*----------------------------------------------------------------------*\
  596.  * set_colour()
  597.  *
  598.  * set draw file line colour.
  599. \*----------------------------------------------------------------------*/
  600. static unsigned int
  601. set_colour(PLColor color)
  602. {
  603.    return  (color.r<<8)|(color.g<<16)|(color.b<<24);
  604. }
  605.  
  606.  
  607. /*----------------------------------------------------------------------*\
  608.  * make_path_hdr()
  609.  *
  610.  * create draw file path header.
  611. \*----------------------------------------------------------------------*/
  612. int
  613. make_path_hdr(PLStream *pls, pldraw_pathstrhdr * oph, pldraw_pathstyle * ps, pldraw_bboxtyp * pbb)
  614. {
  615.         DrawDev *dev = (DrawDev *) pls->dev;
  616.  
  617.         oph->tag = pldraw_OBJPATH;
  618.         set_bbox(pls, 0, 0, 100000, 506000, pbb);
  619.         oph->bbox = *pbb;
  620.         oph->fillcolour = TRANSPARENT;
  621.         oph->pathcolour = set_colour(pls->curcolor);
  622.         oph->pathwidth = (int)(pls->width*dev->xscale_dev);
  623.         ps->joincapwind = 0x42;
  624.         ps->reserved8 = 0;      /* do NOT alter this */
  625.         ps->tricapwid = 10;
  626.         ps->tricaphei = 32;
  627.         oph->pathstyle = *ps;
  628.         return (0);
  629. }
  630.  
  631. /*----------------------------------------------------------------------*\
  632.  * end_obj()
  633.  *
  634.  * end draw file object.
  635. \*----------------------------------------------------------------------*/
  636. int
  637. end_obj(PLStream *pls, pldraw_pathstrhdr * oph)
  638. {
  639.         DrawDev *dev = (DrawDev *) pls->dev;
  640.  
  641.         oph->size = 4 * (10 + dev->path_offset);
  642.         fwrite(oph, 1, sizeof(*oph), pls->OutFile);
  643.         fwrite(dev->path_ptr, 1, 4 * dev->path_offset, pls->OutFile);
  644.         dev->path_offset = 0;
  645.         return (0);
  646. }
  647.  
  648. /*----------------------------------------------------------------------*\
  649.  * add_to_path()
  650.  *
  651.  * add point to draw file path.
  652. \*----------------------------------------------------------------------*/
  653. int
  654. add_to_path(PLStream *pls, int value)
  655. {
  656.         DrawDev *dev = (DrawDev *) pls->dev;
  657.  
  658.         if (dev->path_offset + 1 > dev->path_len)
  659.                 return (-1);
  660.         else {
  661.                 dev->path_ptr[0 + dev->path_offset] = value;
  662.                 return (dev->path_offset = dev->path_offset + 1);
  663.         };
  664. }
  665.  
  666.  
  667. /*----------------------------------------------------------------------*\
  668.  * move_to()
  669.  *
  670.  * move to selected location.
  671. \*----------------------------------------------------------------------*/
  672. int
  673. move_to(PLStream *pls, int x, int y)
  674. {
  675.         add_to_path(pls, 2);
  676.         add_to_path(pls, x*SCALE_FACTOR);
  677.         add_to_path(pls, y*SCALE_FACTOR);
  678.         return (0);
  679. }
  680.  
  681. /*----------------------------------------------------------------------*\
  682.  * line_to()
  683.  *
  684.  * draw a line to selected location.
  685. \*----------------------------------------------------------------------*/
  686. int
  687. line_to(PLStream *pls, int x, int y)
  688. {
  689.     DrawDev *dev = (DrawDev *) pls->dev;
  690.  
  691.         add_to_path(pls, 8);
  692.         add_to_path(pls, (int)(x*dev->xscale_dev));
  693.         add_to_path(pls, (int)(y*dev->yscale_dev));
  694.         return (0);
  695. }
  696.  
  697.  
  698. /*----------------------------------------------------------------------*\
  699.  * close_path()
  700.  *
  701.  * close draw file path.
  702. \*----------------------------------------------------------------------*/
  703. int
  704. close_path(PLStream *pls)
  705. {
  706.         add_to_path(pls, 5);
  707.         return (0);
  708. }
  709.  
  710.  
  711. /*----------------------------------------------------------------------*\
  712.  * end_path()
  713.  *
  714.  * end draw file path.
  715. \*----------------------------------------------------------------------*/
  716. int
  717. end_path(PLStream *pls)
  718. {
  719.         add_to_path(pls, 0);
  720.         return (0);
  721. }
  722.  
  723.  
  724. /*----------------------------------------------------------------------*\
  725.  * rectangle()
  726.  *
  727.  * draw a rectangle of given coordinates.
  728. \*----------------------------------------------------------------------*/
  729. int
  730. rectangle(PLStream *pls, int x0, int y0, int x1, int y1)
  731. {
  732.         move_to(pls, x0, y0);
  733.         line_to(pls, x0, y1);
  734.         line_to(pls, x1, y1);
  735.         line_to(pls, x1, y0);
  736.         line_to(pls, x0, y0);
  737.         return (0);
  738. }
  739.  
  740.  
  741. #else
  742. int
  743. pldummy_arcdraw(void)
  744. {
  745.     return 0;
  746. }
  747.  
  748. #endif        /* PLD_arcdraw */
  749.  
  750.